#!/usr/bin/bash

PATH=/opt/local/gnu/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/usr/sbin
JENKINS_VERSION='2.277'

# Exit if any commands fail
set -o errexit


# Configuring image specific packages
echo "* Configuring image specific packages.";

# Create user for jenkins
echo "* create user for jenkins"
/usr/sbin/groupadd -g 10001 jenkins
/usr/sbin/useradd -u 10001 -g jenkins -d /home/jenkins -m -s /usr/bin/bash jenkins

# Download and enable jenkins
echo "* download and enable jenkins"

/usr/bin/wget --no-check-certificate -O /opt/jenkins.war https://mirrors.tuna.tsinghua.edu.cn/jenkins/war/${JENKINS_VERSION}/jenkins.war


# Clean up
echo "* Cleaning up."
rm -rf /root/*


# Prepare image for provisioning
# only base need, minimal don't need
# gsed -i '/metadata\.sock/d' /opt/local/bin/sm-prepare-image
sm-prepare-image -y
